package top.swimmer.tools.data;

public class IndexOf {
    public static int strStr(String haystack, String needle) {
        char[] haystacks = haystack.toCharArray();
        char[] needles = needle.toCharArray();
        int i = 0;
        int j = 0;
        while (i < haystacks.length && j < needles.length) {
            if (haystacks[i] == needles[j]) {
                i++;
                j++;
            } else {
                i = i - j + 1;
                j = 0;
            }
        }

        return j == needles.length ? i - j : -1;
    }

    public static void main(String[] args) {
        System.out.println(strStr("mississippi", "issip"));
    }
}
